<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      canvas {
        border: 1px solid #ccc;
        margin-right: 5px;
        position: absolute;
      }
      div,img{
        width:300px;
        height: 200px;
        background-color: #fdd;
        text-align: center;
        line-height: 200px;
        font-size: 66px;
        position: absolute;
        user-select: none;
      }
    </style>
    
  </head>
  <body>
    <div>一等奖</div>
    <img src="../imgs/04.png">
    <script>
      (() => {
        const canvas = document.createElement("canvas");
        canvas.width = 300;
        canvas.height = 200;
        document.body.append(canvas);

        const ctx = canvas.getContext("2d");

        ctx.beginPath();
        ctx.fillStyle='#ccc';
        ctx.fillRect(0,0,300,200);

        ctx.globalCompositeOperation = 'destination-out';

        ctx.beginPath();
        ctx.strokeStyle = '#fff';
        ctx.lineWidth = 20 ;
        ctx.lineCap = 'round' ;   
        ctx.lineJoin = 'round' ; 

        canvas.onmousedown = function(e){
            ctx.moveTo(e.offsetX,e.offsetY);

            canvas.onmousemove = function(e){
              ctx.lineTo(e.offsetX,e.offsetY) ;
              ctx.stroke();
            }

            canvas.onmouseup = canvas.onmouseout = function(){
              canvas.onmousemove = null ;
              canvas.onmouseout = null ;

            }

        }

      })();
    </script>
  </body>
</html>
